import Vue from 'vue'
import App from './App.vue'
import ViewUI from 'view-design';
import axios from 'axios';

import { Chart } from '@antv/g2';
import DataSet from '@antv/data-set';

import 'view-design/dist/styles/iview.css';
import router from './router';
import store from './store';
import './rem';
import './assets/common.css'
import urls from './common'

Vue.prototype.$http=axios;
Vue.prototype.dealThing=0;
Vue.prototype.urls=urls;
Vue.prototype.DataSet=DataSet;
Vue.prototype.settimes='';
Vue.config.productionTip = false;
Vue.use(ViewUI);
// Vue.use(Chart);

// import {Spin} from 'view-design'

Vue.prototype.needDeal=function(){
  axios.get('/api2'+this.urls.getTodoCaseCount).then((result)=>{
      if(result.data.code===200){
        // this.dealThing=result.data.data.count
        this.$store.commit('dealThing', result.data.data.count)
      }else{
        this.$Message.warning('网络错误');
      }
  })
};

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

new Vue({
  router,
  store,
  render: h =>h(App),
  watch:{
    $route(to,from){
      if(to.name=='Login'||to.name=='verifyApplyedNotice'||to.name=='verifyApplyNotice'||
          to.name=='SelectArbitrator'){
        return false;
      }
      if(localStorage.getItem('userplatname')){
        if(localStorage.getItem('roleplatid')=='financeCompany'
           &&to.path.indexOf('Applypage')<0){
             this.$router.push('/');
        }else if(localStorage.getItem('roleplatid')=='admin'
        &&to.path.indexOf('Analysis')<0){
             this.$router.push('/');
        }
      }else{
        this.$router.push('/');
      }
    }
  },
  created(){
    if(this.$route.name=='Login'||this.$route.name=='verifyApplyedNotice'||
      this.$route.name=='verifyApplyNotice'||this.$route.name=='SelectArbitrator'){
      return false;
    }
    if(localStorage.getItem('userplatname')){
        if(localStorage.getItem('roleplatid')=='financeCompany'
            &&this.$route.path.indexOf('Applypage')<0){
              this.$router.push('/');
        }else if(localStorage.getItem('roleplatid')=='admin'
        &&this.$route.path.indexOf('Analysis')<0){
              this.$router.push('/');
        }else if(localStorage.getItem('roleplatid')=='arbDataEntry'
        &&this.$route.path.indexOf('bankInsert')<0){
              this.$router.push('/');
        }
    }else{
      this.$router.push('/');
      
    }
  }
}).$mount('#app')
